package cn.wolfcode.mycat.controller;

import cn.wolfcode.mycat.domain.ReceiveErpRecordEntity;
import cn.wolfcode.mycat.service.ESRestService;
import cn.wolfcode.mycat.service.ElasticsearchReceiveErpRecordService;
import com.alibaba.fastjson.JSON;
import com.godbean.wuji.commons.util.GbDate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/es")
@Api(value = "ESRestController服务", tags = "ESRestController服务")
public class ESRestController {

    @Autowired
    private ESRestService service;
    @Autowired
    private ElasticsearchReceiveErpRecordService elasticsearchReceiveErpRecordService;
    
    @GetMapping("/erp/callback")
    @ApiOperation("ERP回调")
    public String testErpReceive() {
	    ReceiveErpRecordEntity receiveErpRecordEntity = new ReceiveErpRecordEntity();
	    receiveErpRecordEntity.setRecordCode("tid1231231231");
	    receiveErpRecordEntity.setOwnerCode("DP0001");
	    receiveErpRecordEntity.setWarehouseCode("L123123123123");
	    receiveErpRecordEntity.setOrderType("Report");
	    receiveErpRecordEntity.setSystemCode("Qimen_WDT_ERP");
	    receiveErpRecordEntity.setRequestService("qimen.logistics.report");
	    receiveErpRecordEntity.setRequestUrl("http://test.com/qimen/api/outservice/erp/receiveMessage");
	    receiveErpRecordEntity.setRequestContent("testcontent");
	    receiveErpRecordEntity.setResponseContent("平台物流同步-通知成功");
	    receiveErpRecordEntity.setCreateTime(GbDate.now());
	    receiveErpRecordEntity.setStatus(1);
	    return elasticsearchReceiveErpRecordService.save(receiveErpRecordEntity);
    }

    @PostMapping("/add")
    @ApiOperation("增加数据")
    public String add() {
        return service.add();
    }

    @PostMapping("/update")
    @ApiOperation("修改数据")
    public String update() {
        return service.update();
    }

    @PostMapping("/insertBatch")
    @ApiOperation("批量增加数据")
    public String insertBatch() {
        return service.insertBatch();
    }

    @PostMapping("/deleteByQuery")
    @ApiOperation("根据条件删除")
    public void delete() {
        service.delete();
    }

    @PostMapping("/deleteById")
    @ApiOperation("根据id删除")
    public String deleteById() {
        return service.deleteById();
    }

    @PostMapping("/searchData")
    @ApiOperation("根据条件查询")
    public List searchData() {
        return service.searchData();
    }


}
